﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ResourcePopupSelector.ascx.cs"
	ClassName="ResourcePopupSelector" Inherits="Hxsoft.AppV1._Controls.ResourcePopupSelector" %>
<%@ Register Src="ResourceSelector.ascx" TagName="ResourceSelector" TagPrefix="Hxctr" %>
<span id="<%= this.ClientID %>">
	<asp:HiddenField ID="CtrSelectorValue" runat="server" />
	<div class="ResourcePopupSelectorPreviewImageBox">
		<asp:Image ID="CtrImagePreview" AlternateText="Preview" runat="server" /></div>
	<div class="ResourcePopupSelectorButtonView">
		<a id="<%= this.ClientID %>_CtrUploadButton" href="javascript:void(0);">
			<%= UploadText %></a> <a href="javascript:<%= this.ClientID %>_CancelValue();">
				<%= CancelText %></a> <%= OtherUrlText %>：<input id="<%= this.ClientID %>_CtrCustom" type="text" /><input
					id="<%= this.ClientID %>_CtrCustomPreview" type="button" value="<%= AddText %>" />
	</div>
	<div id="CtrPopupSelector" class="ResourcePopupSelectBox" runat="server">
		<Hxctr:ResourceSelector ID="CtrResourceSelector" IsStartLoadData="false" PageSize="8"
			runat="server" />
	</div>
</span>

<script type="text/javascript">
function <%= this.ClientID %>_SetValue(resourceInfo)
{
	this.getPreviewResourceUrl = <%= InfoResourceThumbnailGeneratorUrl_ClientScript %>;
	
	var resourceId = "", resourceType = "", value = "", previewUrl = "<%= Hxsoft.AppV1.ApplicationConfiguration.ResourcePopupSelectorFolderUrl %>NotImage.jpg";
	if(resourceInfo)
	{
		resourceId = resourceInfo.resourceId;
		resourceType = resourceInfo.resourceType;
		value = resourceId + (resourceType ? "." + resourceType : "");
		previewUrl = this.getPreviewResourceUrl(resourceId, "<%= PreviewCopyName %>", resourceType);
	}

	$("#<%= CtrImagePreview.ClientID %>").attr("src", previewUrl).attr("alt", value);
	$("#<%= CtrSelectorValue.ClientID %>").val(value);
	$("#<%= CtrPopupSelector.ClientID %>").css("display", "none");
}

function <%= this.ClientID %>_SetCustomValue()
{
	var url = $("#<%= this.ClientID %>_CtrCustom").val();
	var previewUrl = "<%= Hxsoft.AppV1.ApplicationConfiguration.ResourcePopupSelectorFolderUrl %>NotImage.jpg";
	if(url) previewUrl = url;
	
	$("#<%= CtrImagePreview.ClientID %>").attr("src", previewUrl).attr("alt", url);
	$("#<%= CtrSelectorValue.ClientID %>").val(url);
}

function <%= this.ClientID %>_CancelValue()
{
	<%= this.ClientID %>_SetValue(null);
}

function <%= this.ClientID %>_Init()
{
	$("#<%= this.ClientID %>_CtrUploadButton").bind("click", <%= CtrResourceSelector.ClientID %>_Reload);
	$("#<%= this.ClientID %>_CtrUploadButton").popupElement({popupElement : "#<%= CtrPopupSelector.ClientID %>"});
	$("#<%= this.ClientID %>_CtrCustom").change(<%= this.ClientID %>_SetCustomValue);
	$("#<%= this.ClientID %>_CtrCustomPreview").click(<%= this.ClientID %>_SetCustomValue);
}
</script>

